using MicroMsg.Common.Event;
using MicroMsg.Manager;
using MicroMsg.Protocol;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace MicroMsg.UI.Page
{
	public class LogByPhonePassword : BasePage
	{
		private EventWatcher mWatcherLogin;
		internal Grid LayoutRoot;
		internal panelTitle2Line panelTitle;
		internal WaterMarkPassWordBox textBoxPassWord;
		internal Button btnLogin;
		internal Button btnForgetPassword;
		private bool _contentLoaded;
		public LogByPhonePassword()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.LogByPhonePassword_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.LogByPhonePassword_Unloaded));
		}
		private void LogByPhonePassword_Loaded(object sender, RoutedEventArgs e)
		{
			this.registerEvent();
		}
		private void LogByPhonePassword_Unloaded(object sender, RoutedEventArgs e)
		{
			this.unRegisterEvent();
		}
		private void registerEvent()
		{
			if (this.mWatcherLogin == null)
			{
				this.mWatcherLogin = new EventWatcher(this, this, new EventHandlerDelegate(this.onLoginEventHandler));
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_AUTH_ERR, this.mWatcherLogin);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_AUTH_SUCCESS, this.mWatcherLogin);
			}
		}
		private void unRegisterEvent()
		{
			if (this.mWatcherLogin != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_AUTH_ERR, this.mWatcherLogin);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_AUTH_SUCCESS, this.mWatcherLogin);
				this.mWatcherLogin = null;
			}
		}
		private void onLoginEventHandler(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			this.enableAllControls();
			if (EventConst.ON_NETSCENE_AUTH_SUCCESS == evtArgs.mEventID)
			{
				InputVCodeControl.DismissInputVcodeBox();
				MessageBoxManager.ShowToast(strings.Login_Main_MsgLogSucc, 2500, null, false);
				PageManager.getInstance().PopAllPages(true);
				RetConst retConst = RetConst.MM_OK;
				if (evtArgs.mObject != null && evtArgs.mObject is RetConst)
				{
					retConst = (RetConst)evtArgs.mObject;
				}
				GConfigMgr.settings.strLastLoginName = LoginMainView.sStrNameToLogin;
				GConfigMgr.saveSetting();
				MainPage.GotoThisPage(new object[]
				{
					true,
					retConst
				}, true);
				return;
			}
			int num = -(int)evtArgs.mObject;
			if (-6 == num)
			{
				return;
			}
			this.processLoginErr(evtArgs);
			InputVCodeControl.DismissInputVcodeBox();
		}
		private void processLoginErr(BaseEventArgs evtArgs)
		{
			RetConst retConst = (RetConst)evtArgs.mObject;
			RetConst retConst2 = retConst;
			if (retConst2 == RetConst.MM_ERR_CLIENT)
			{
				MMMessageBox.Show(strings.Login_Main_MsgBadNet, true, "确定");
				return;
			}
			MMMessageBox.Show(strings.Login_Main_MsgBadAcc, true, "确定");
		}
		private void textBoxPassWord_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.get_Key() == 3 && sender == this.textBoxPassWord)
			{
				base.Focus();
				this.btnLogin_Click(null, null);
			}
		}
		private void btnLogin_Click(object sender, RoutedEventArgs e)
		{
			if (this.textBoxPassWord.Password == "")
			{
				MessageBoxManager.ShowToast(strings.Login_Main_MsgNoPass, 2500, null, false);
				return;
			}
			if (!TestUserChecker.IsTestUser(LoginMainView.sStrNameToLogin))
			{
				MMMessageBox.Show("对不起，你还不是指定的测试用户。", true, "确定");
				return;
			}
			this.disableAllControls();
			ServiceCenter.sceneAuth.doScene(LoginMainView.sStrNameToLogin, this.textBoxPassWord.Password);
		}
		private void btnForgetPassword_Click(object sender, RoutedEventArgs e)
		{
			base.GoToPage("/Source/UI/LoginViews/ForgetPasswordView.xaml", null, false);
		}
		private void enableAllControls()
		{
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
		}
		private void disableAllControls()
		{
			ProcessingCover.getProgressBar(this.LayoutRoot, strings.Login_Main_MsgSending, null, false, false, null);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/LoginViews/LogByPhonePassword.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.panelTitle = (panelTitle2Line)base.FindName("panelTitle");
			this.textBoxPassWord = (WaterMarkPassWordBox)base.FindName("textBoxPassWord");
			this.btnLogin = (Button)base.FindName("btnLogin");
			this.btnForgetPassword = (Button)base.FindName("btnForgetPassword");
		}
	}
}
